
import subprocess
import os


# try:
#     cmd=["mkdir","inserted"]
#     subprocess.run(cmd)
# except:
#     print("file has registed.")

path_="./babel/"

files =os.listdir("./babel")
files_file = [f for f in files if os.path.isfile(os.path.join("./babel", f))]
print("-------list of element--------")
print(files_file)
for i in files_file:
    filename = path_ + i
    print(filename)
    try:
        with open(filename) as e:
            ary = e.readlines()
            try:
                ary.pop(1)
            except:
                None
            print(ary)
            with open(filename,"w") as d :
                d.writelines(ary)

        try:
            with open(filename) as f:
                line = f.readlines()
            line.insert(1,'#P B3LYP/6-31G** OPT FREQ IOP(3/24=10,6/7=3)\n')
            with open(filename,"w") as g:
                g.writelines(line)
                print("edited")
        except:
            print("Error.check source file.")
    except FileNotFoundError:
        print("Failed")
        # errorname = "./error log" 
        # with open(errorname) as er:
        #     errortext = filename + "is fail has the empty.\ncheck the source file."
        #     er.write(errortext)
        